package servlets;

import java.io.IOException;
import java.util.LinkedList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import bean.ArticleAdm;
import bean.Articles;
import bean.Participate;
import bean.ParticipateAdm;

@SuppressWarnings("serial")
public class ArtManServlet extends HttpServlet{
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		int num = Integer.parseInt(req.getParameter("num"));
		
		HttpSession session = req.getSession();
		long id = (Long)session.getAttribute("id");
		
		ArticleAdm aa = new ArticleAdm();
		List<Articles> art = aa.searchByMem(id);
		
		ParticipateAdm pa = new ParticipateAdm();
		List<Participate> part = pa.searchByAddMem(id);
		
		List<Articles> art2 = new LinkedList<Articles>();
		for(Participate p:part){
			Articles a = p.getArticle();
			art2.add(new Articles(a.getKey(), a.getCreateUserID(), a.getCategory(), a.getArtName(), 
					a.getPrice(), a.getShipWay(), a.getBuyDate(), a.getBranch(), a.getTotalAmount(), 
					a.getRemainAmount(), a.getLeftAmount(), a.getShipFee(), a.getNote()));
		}
		
		
		req.setAttribute("articles1", art);
		req.setAttribute("articles2", art2);
		req.setAttribute("num", num);
		
		if(num==1){
			req.getRequestDispatcher("./member/GroupIng.jsp").forward(req, resp);
		}else if(num==2){
			req.getRequestDispatcher("./member/GroupFinshed.jsp").forward(req, resp);
		}		
	}
}
